<!DOCTYPE html>
<html>
<head>
  <title></title>
  <meta charset="utf-8">
  <script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<form action="http://localhost:8080" method="post">
用户名：<input type="text" name="" id="user"><br/>
密码：<input type="password" name="" id="pass"><br/>

<input type="button" value="注册" name="" id="btn1">
<input type="button" value="登录" name="" id="btn2">
</form>
<script type="text/javascript">
var oUser=document.getElementById('user');
var oPass=document.getElementById('pass');
var oBtn1=document.getElementById('btn1');
var oBtn2=document.getElementById('btn2');

oBtn1.onclick=function(){
  //ajax请求
  ajax({
    url:'/sign.html',
    data:{user:oUser.value,pass:oPass.value
    },
    success:function(str){
      // console.log(str);
      var json=JSON.parse(str);
      if (json.ok) {
        alert('注册成功');
      }else{
        alert('注册失败');
      }
    },
    error:function(){
      console.log('err');
    }
  })
}
oBtn2.onclick=function(){
  //ajax请求
  ajax({
    url:'/sign2.html',
    data:{user:oUser.value,pass:oPass.value
    },
    success:function(str){
      // console.log(str);
      var json=JSON.parse(str);
      if (json.ok) {
        alert('登录成功');
      }else{
        alert('登录失败');
      }
    },
    error:function(){
      console.log('err');
    }
  })
}
</script>
</body>
</html>
